package com.spark.vector

import org.apache.spark.mllib.linalg
import org.apache.spark.mllib.linalg.{Matrices, Matrix, Vectors}
import org.apache.spark.mllib.regression.LabeledPoint

/**
  * Created by TRS on 2017/6/27.
  */
object localVector {
  def main(args: Array[String]): Unit = {



    val sv1: linalg.Vector = Vectors.sparse(4, Array(0, 2), Array(1.0, 3.0))

    val sv2: linalg.Vector = Vectors.sparse(5, Seq((0, 1.0), (2, 3.0)))


    println(sv1.toDense)
    println(sv2.toDense)



    val pos = LabeledPoint(1.0, Vectors.dense(1.0, 0.0, 3.0))
    println(pos)


    val neg = LabeledPoint(0.0, Vectors.sparse(3, Array(0, 2), Array(1.0, 3.0)).toDense)
    println(neg)

    // Create a dense matrix ((1.0, 2.0), (3.0, 4.0), (5.0, 6.0))
    val dm: Matrix = Matrices.dense(3, 2, Array(1.0, 3.0, 5.0, 2.0, 4.0, 6.0))

    println(dm)

    // Create a sparse matrix ((9.0, 0.0), (0.0, 8.0), (0.0, 6.0))
    val sm: Matrix = Matrices.sparse(3, 2, Array(0, 1, 3), Array(0, 2, 1), Array(9, 6, 8))


  }

}
